home *** CD-ROM | disk | FTP | other *** search
/ The World's Largest Collection of Windows Software / The World's Largest Collection of Windows Software - Disc 1.iso / connect / _j2 / wvnsc926 / rcs / ini_news.c < prev    next >
C/C++ Source or Header  |  1994-09-21  |  46KB  |  1,780 lines

  1. head     1.6;
  2. branch   ;
  3. access   ;
  4. symbols  V80:1.1 V76d:1.1;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.6
  10. date     94.09.15.22.23.09;  author brydon;  state Exp;
  11. branches ;
  12. next     1.5;
  13.  
  14. 1.5
  15. date     94.09.06.12.46.21;  author brydon;  state Exp;
  16. branches ;
  17. next     1.4;
  18.  
  19. 1.4
  20. date     94.02.17.19.49.53;  author brydon;  state Exp;
  21. branches ;
  22. next     1.3;
  23.  
  24. 1.3
  25. date     93.12.08.01.28.01;  author rushing;  state Exp;
  26. branches ;
  27. next     1.2;
  28.  
  29. 1.2
  30. date     93.07.07.19.52.22;  author rushing;  state Exp;
  31. branches ;
  32. next     1.1;
  33.  
  34. 1.1
  35. date     93.02.16.20.53.50;  author rushing;  state Exp;
  36. branches ;
  37. next     ;
  38.  
  39.  
  40. desc
  41. @winvn version 0.76 placed into RCS
  42. @
  43.  
  44.  
  45. 1.6
  46. log
  47. @allow config files with read-only/archive/system bits set
  48. @
  49. text
  50. @/*
  51.  *                              
  52.  * $Id: ini_news.c 1.5 1994/09/06 12:46:21 brydon Exp $
  53.  * $Log: ini_news.c $
  54.  * Revision 1.5  1994/09/06  12:46:21  brydon
  55.  * win32 fixes, comments changed
  56.  *
  57.  * Revision 1.5  1994/08/09  15:30:00  brydon
  58.  * More searching, OPENFILENAME logic fix
  59.  *
  60.  * Revision 1.4  1994/02/17  19:49:53  brydon
  61.  * cleanup and fixes for win32
  62.  *
  63.  * Revision 1.3  1993/12/08  01:28:01  rushing
  64.  * new version box and cr lf consistency
  65.  *
  66.  * Revision 1.2  1993/07/07  19:52:22  rushing
  67.  * check value returned from getenv for NULL
  68.  *
  69.  * Revision 1.1  1993/02/16  20:53:50  rushing
  70.  * Initial revision
  71.  *
  72.  *
  73.  */
  74.  
  75. /*#*xx********************************************************************/
  76. /* Filename: Ini-News.c */
  77.  
  78. #include <windows.h>
  79. #include <stdlib.h>
  80. #include <direct.h>
  81. #include "WvGlob.h"
  82. #include <time.h>
  83. #include <commdlg.h>
  84.  
  85. #ifdef WIN32   /* Looks like SDK defines "WIN32", MSVCNT defines "_WIN32" */
  86. #ifndef _WIN32
  87. #define _WIN32
  88. #endif
  89. #endif
  90.  
  91. #ifndef TRACE
  92. #ifdef _DEBUG
  93. char    szDebugBuffer[80];
  94. #define TRACE(parm1,parm2) {\
  95.     wsprintf(szDebugBuffer,parm1,parm2);\
  96.     OutputDebugString(szDebugBuffer);}
  97. #else
  98. #define TRACE(parm1,parm2)
  99. #endif
  100. #endif
  101.  
  102. #define PROFTYPE "Admin"
  103.  
  104. /*************************************************************************
  105.   This function looks for the .Ini file and the NewsSrc file.  Each file
  106.   is searched for separately and they need not be in the same directory.
  107.   If neither file can be found, the user is asked to locate the files with
  108.   an OPENFILENAME dialog box.  Once the location of the NewSrc file is
  109.   known, it is saved in the WinVN.ini file.
  110.  
  111.   The search order is:
  112.     Command Line (one or two entries)
  113.     Environment variable "WINVN" or "winvn" (case sensitive in Win16)
  114.     Current Working directory (set by "Properties" dialog)
  115.     Application Directory
  116.     Windows Directory (eg. C:\WINDOWS)
  117.     Windows System Directory (eg. C:\WINDOWS\SYSTEM, \System32)
  118.     the path
  119.     result of an "Open File" dialog box (WinVN.ini only)
  120.     the .INI file (NewSrc only)
  121.     result of an "Open File" dialog box (NewSrc only)
  122.  
  123.  
  124.   If the Function is sucessful, the szAppProFile variable contains the path and
  125.   filename of the .Ini file and the szNewsSrc variable contains the path and
  126.   filename of the NewSrc file.  If either file does not exist, the "Open
  127.   File" dialog creates each file.  In all cases, the name of the NewSrc
  128.   file is written to the .INI file for future accesses.
  129.  
  130.   RETURNS:  zero if sucessful
  131.             -1 if one or both files could not be found
  132.  
  133.   NOTE: The command line allows for the use of unique names for the standard
  134.         WinVn.ini and NewSrc files. The entry order is .Ini and then NewSrc.
  135.  
  136.  Command line examples are as follows:
  137.  
  138.   1.  c:\WinVn\My.Ini<sp>c:\Tom\NewsSrc.Tom  => both unique names
  139.  
  140.   2.  c:\Tom<sp>c:\Tom\NewsSrc.Tom        => standard .Ini, unique NewSrc
  141.   2a. c:\Tom\<sp>c:\Tom\NewsSrc.Tom          (same, less ambiguous)
  142.  
  143.   3.  c:\Tom\TomVn.ini                    => unique .Ini, Standard NewSrc
  144.  
  145.   4.  c:\Tom                              => standard .Ini, Standard NewSrc
  146.   4a. c:\Tom\                                (same, less ambiguous)
  147.  
  148.   In the first example, if both files exist, szAppProFile = "c:\WinVn\My.Ini",
  149.   szNewsSrc = "c:\Tom\NewsSrc.Tom" and the function returns Zero.
  150.  
  151.  For all specification types other than the Command line:
  152.  1. Only one entry may be made.
  153.  2. The "Working directory" spec doesn't allow trailing "\".
  154.  3. Syntax and algorithm are otherwise the same as for Command Line.
  155.  
  156. **************************************************************************/
  157.  
  158. #define CHECK_DIR 1
  159. #define CHECK_FILE 2
  160.  
  161. /*  Routine to test existence of filename on path choice */
  162. BOOL ProbeFilePath(char *szFileSrc, char *szPath, char *szFname, int iChk)
  163.   DWORD stat;
  164.   OFSTRUCT ofb;
  165.  
  166.   /* Check for path in the form of "x:\dir\...\dir[\]" */
  167.   if(iChk & CHECK_DIR)
  168.   {
  169.     int i;
  170.     lstrcpy(szFileSrc, szPath);
  171.     i = lstrlen(szFileSrc);
  172.     if(i)
  173.     {
  174.       if (szFileSrc[i-1] == '\\')  /* Trailing '\', it must be a directory */
  175.       {
  176.         lstrcat(szFileSrc, szFname);
  177.         if (OpenFile (szFileSrc, &ofb, OF_EXIST) != HFILE_ERROR)
  178.         {
  179.           lstrcpy(szFileSrc, ofb.szPathName);
  180.           return (TRUE);
  181.         }
  182.         else
  183.           return(FALSE);
  184.       }
  185.     }
  186. #ifdef GetFileAttributes  /*  32 bit  */
  187.     stat = GetFileAttributes(szFileSrc);
  188.     if((stat != 0xFFFFFFFF) && (stat & FILE_ATTRIBUTE_DIRECTORY))
  189. #else                     /*  16 bit  */
  190.     stat = 0;  /* avoid 'unreferenced' warning */
  191.     if(TRUE)
  192. #endif
  193.     {
  194.       lstrcat(szFileSrc, "\\");
  195.       lstrcat(szFileSrc, szFname);
  196.       if (OpenFile (szFileSrc, &ofb, OF_EXIST) != HFILE_ERROR)
  197.       {
  198.         lstrcpy(szFileSrc, ofb.szPathName);
  199.         return TRUE;
  200.       }
  201.     }
  202.   }
  203.   
  204.   /* Check for non-directory file in the form of "x:\dir\...\dir\file.ext" */
  205.   if (iChk & CHECK_FILE)
  206.   {
  207.     lstrcpy(szFileSrc, szPath);
  208.  
  209. #ifdef GetFileAttributes
  210.     if (GetFileAttributes(szFileSrc) & FILE_ATTRIBUTE_DIRECTORY)
  211.       return(FALSE);
  212. #endif
  213.  
  214.     if (OpenFile (szFileSrc, &ofb, OF_EXIST) != HFILE_ERROR)
  215.     {
  216.       lstrcpy(szFileSrc, ofb.szPathName);
  217.       return TRUE;
  218.     }
  219.   }
  220.   return FALSE;
  221. }
  222.  
  223.  
  224.  
  225. /*  See if we can find the WinVN.ini and NewSrc files... */
  226. int LocIniSrc(HINSTANCE hInstance, LPSTR lpCmdLine)
  227. {
  228.   char szWPath[256];
  229.   
  230.   char szIniDef[] = "WinVN.ini";   /* ' .ini' default filename */
  231.   char szNewsDefault[] = "NewSrc"; /* 'newsrc' default filename  */
  232.  
  233.   BOOL fProfileFound = FALSE;
  234.   BOOL fNewsFound = FALSE;
  235.  
  236.   int iRvalue;
  237.  
  238.   LPSTR lpEnvStr;
  239.   OFSTRUCT ofOpenBuffer;
  240.  
  241.   ofOpenBuffer.cBytes = sizeof (OFSTRUCT);
  242.  
  243.      
  244.   if (*lpCmdLine != '\0')  /* Look at the Command Line */
  245.   {           /* path | path and file */
  246.     lstrcpy (szWPath, lpCmdLine);
  247.     TRACE("Checking Command Line: %s\n", szWPath);
  248.     iRvalue = lstrlen (szWPath);
  249.  
  250.     while (iRvalue--)
  251.     {           /* check for two arguments */
  252.       if (szWPath[iRvalue] == ' ')
  253.       { szWPath[iRvalue] = 0;
  254.         break;
  255.       }
  256.     }
  257.  
  258.     if (iRvalue > 0)
  259.     { /* two entries on command line - check for path and/or path\file */
  260.       fProfileFound = ProbeFilePath(szAppProFile, szWPath,
  261.         szIniDef, CHECK_DIR | CHECK_FILE);
  262.       fNewsFound = ProbeFilePath(szNewsSrc, &szWPath[iRvalue + 1], 
  263.         szNewsDefault, CHECK_FILE);
  264.     }
  265.  
  266.     else
  267.     { /* single command line entry - path and/or path\file */
  268.       fProfileFound = ProbeFilePath(szAppProFile, szWPath,
  269.         szIniDef, CHECK_DIR | CHECK_FILE);
  270.       fNewsFound = ProbeFilePath(szNewsSrc, szWPath,
  271.         szNewsDefault, CHECK_DIR);
  272.     }
  273.   if(fProfileFound && fNewsFound) return 0;
  274.   }
  275.  
  276.     
  277.  
  278.       /* Look in the Environment for a path */
  279.   if ((lpEnvStr = getenv ("winvn")) == NULL)
  280.   {
  281.     lpEnvStr = getenv ("WINVN");
  282.   }
  283.  
  284.   if (lpEnvStr && (iRvalue = lstrlen(lpEnvStr)))
  285.   {           /* found environment varible, check it out */
  286.     lstrcpy (szWPath, lpEnvStr);
  287.     
  288.     TRACE("Checking environment var: %s\n", szWPath);
  289.     if (!fProfileFound)
  290.       fProfileFound = ProbeFilePath(szAppProFile, szWPath,
  291.         szIniDef, CHECK_DIR | CHECK_FILE);
  292.  
  293.     if (!fNewsFound)
  294.       fNewsFound = ProbeFilePath(szNewsSrc, &szWPath[iRvalue + 1], 
  295.         szNewsDefault, CHECK_DIR | CHECK_FILE);
  296.  
  297.     if (fProfileFound && fNewsFound)
  298.       return 0;
  299.   }
  300.  
  301.  
  302.  
  303.   /* Look in the current working Directory */
  304.   if (_getcwd(szWPath, sizeof(szWPath)))
  305.   {
  306.     TRACE("Checking current working directory: %s\n", szWPath);
  307.     if (!fProfileFound)
  308.       fProfileFound = ProbeFilePath(szAppProFile, szWPath,
  309.         szIniDef, CHECK_DIR);
  310.  
  311.     if (!fNewsFound)
  312.       fNewsFound = ProbeFilePath(szNewsSrc, szWPath,
  313.         szNewsDefault, CHECK_DIR);
  314.  
  315.     if (fProfileFound && fNewsFound) return 0;
  316.   }
  317.  
  318.  
  319.  
  320.   /* Look in WinVn's Directory */
  321.   if (iRvalue = GetModuleFileName(hInstance, szWPath, sizeof(szWPath)))
  322.   {
  323.     while (iRvalue--)
  324.     {           /* remove the module name */
  325.       if (szWPath[iRvalue] == '\\')
  326.       { szWPath[++iRvalue] = 0;
  327.         break;
  328.       }
  329.     }
  330.  
  331.     TRACE("Checking WinVN directory: %s\n", szWPath);
  332.     if (!fProfileFound)
  333.       fProfileFound = ProbeFilePath(szAppProFile, szWPath,
  334.         szIniDef, CHECK_DIR);
  335.  
  336.     if (!fNewsFound)
  337.       fNewsFound = ProbeFilePath(szNewsSrc, szWPath,
  338.         szNewsDefault, CHECK_DIR);
  339.  
  340.     if (fProfileFound && fNewsFound) return 0;
  341.   }
  342.  
  343.  
  344.  
  345.   /* Look in the Windows Directory */
  346.   if (GetWindowsDirectory(szWPath, sizeof(szWPath)))
  347.   {
  348.     TRACE("Checking Windows directory: %s\n", szWPath);
  349.     if (!fProfileFound)
  350.       fProfileFound = ProbeFilePath(szAppProFile, szWPath,
  351.         szIniDef, CHECK_DIR);
  352.  
  353.     if (!fNewsFound)
  354.       fNewsFound = ProbeFilePath(szNewsSrc, szWPath,
  355.         szNewsDefault, CHECK_DIR);
  356.  
  357.     if (fProfileFound && fNewsFound) return 0;
  358.   }
  359.  
  360.  
  361.  
  362.   /* Look in the Windows System Directory */
  363.   if (GetSystemDirectory (szWPath, sizeof(szWPath)))
  364.   {
  365.     TRACE("Checking Windows System directory: %s\n", szWPath);
  366.     if (!fProfileFound)
  367.       fProfileFound = ProbeFilePath(szAppProFile, szWPath,
  368.         szIniDef, CHECK_DIR);
  369.  
  370.     if (!fNewsFound)
  371.       fNewsFound = ProbeFilePath(szNewsSrc, szWPath,
  372.         szNewsDefault, CHECK_DIR);
  373.  
  374.     if (fProfileFound && fNewsFound) return 0;
  375.   }
  376.  
  377.  
  378.  
  379.   /* Try the current path */
  380.   szWPath[0] = '\0';
  381.   TRACE("Checking path\n", "");
  382.   if (!fProfileFound)
  383.     fProfileFound = ProbeFilePath(szAppProFile, szWPath,
  384.       szIniDef, CHECK_DIR);
  385.  
  386.   if (!fNewsFound)
  387.     fNewsFound = ProbeFilePath(szNewsSrc, szWPath,
  388.       szNewsDefault, CHECK_DIR);
  389.  
  390.   if (fProfileFound && fNewsFound) return 0;
  391.   else
  392.   { /* Ask the user if he wants to create the files */
  393.     static OPENFILENAME ofn;
  394.  
  395.     ofn.lStructSize       = sizeof(OPENFILENAME);
  396.     ofn.hwndOwner         = NULL;
  397.     ofn.hInstance         = NULL;
  398.  /* ofn.lpstrFilter       = (Filled in below)  */
  399.     ofn.lpstrCustomFilter = NULL;
  400.     ofn.nMaxCustFilter    = 0;
  401.     ofn.nFilterIndex      = 0;
  402.  /* ofn.lpstrFile         = (Filled in below)  */
  403.  /* ofn.nMaxFile          = (Filled in below)  */
  404.     ofn.lpstrFileTitle    = NULL;
  405.     ofn.nMaxFileTitle     = 0;
  406.     ofn.lpstrInitialDir   = szWPath;
  407.     ofn.lpstrTitle        = "Please identify existing or new filename";
  408.     ofn.Flags             =
  409.       OFN_CREATEPROMPT
  410. #ifdef OFN_NONETWORKBUTTON
  411.       | OFN_NONETWORKBUTTON
  412. #endif    
  413.       | OFN_NOREADONLYRETURN;
  414.     ofn.nFileOffset       = 0;
  415.     ofn.nFileExtension    = 0;
  416.  /* ofn.lpstrDefExt       = (Filled in below)  */
  417.     ofn.lCustData         = 0L;
  418.     ofn.lpfnHook          = NULL;
  419.     ofn.lpTemplateName    = NULL;
  420.  
  421.     if (!fProfileFound)
  422.     {
  423.       char szCreated[32];
  424.  
  425.       ofn.lpstrFilter       =
  426.         "Init Files (*.INI)\0*.ini\0All Files (*.*)\0*.*\0";
  427.       lstrcpy (szAppProFile, szIniDef);
  428.       ofn.lpstrFile         = szAppProFile;
  429.       ofn.nMaxFile          = sizeof(szAppProFile);
  430.       ofn.lpstrDefExt       = "INI";
  431.    
  432.       TRACE("Checking user-specified filename\n", "");
  433.       fProfileFound = GetOpenFileName(&ofn);
  434.       if (fProfileFound)
  435.       {
  436.         char dbuffer[9];
  437.         char tbuffer[9];
  438.         OFSTRUCT ofs;
  439.  
  440.      /* ofn.lpstrInitialDir = ...  */
  441.      
  442.         if (OpenFile(szAppProFile, &ofs, OF_EXIST) == HFILE_ERROR)
  443.         {
  444.           _strdate(dbuffer);
  445.           _strtime(tbuffer);
  446.    
  447.           TRACE("Writing new WinVN.INI file to %s\n", szAppProFile);
  448.           lstrcpy(szCreated, dbuffer);
  449.           lstrcat(szCreated, " ");
  450.           lstrcat(szCreated, tbuffer);
  451.    
  452.           WritePrivateProfileString(PROFTYPE, "Created",
  453.             szCreated, szAppProFile);
  454.         }
  455.       }
  456.     }
  457.  
  458.  
  459.     /* Look for NewSrc spec in WinVN.INI */
  460.     if (fProfileFound && !fNewsFound)
  461.     {
  462.       TRACE("Checking %s for NewSrc file", szAppProFile);
  463.       if(GetPrivateProfileString(PROFTYPE, "Newsrc", "",
  464.          szNewsSrc, sizeof(szNewsSrc), szAppProFile))
  465.       {
  466.         OFSTRUCT ofs;
  467.         fNewsFound = (OpenFile(szNewsSrc, &ofs, OF_EXIST) != HFILE_ERROR);
  468.       }
  469.     }
  470.  
  471.  
  472.     /* Give up?  Ask the user where the file is... */
  473.     if (fProfileFound && !fNewsFound)
  474.     {
  475.       ofn.lpstrFilter       =
  476.         "No-ext Files (*.)\0*.\0All Files (*.*)\0*.*\0";
  477.       ofn.nFilterIndex      = 0;
  478.       lstrcpy (szNewsSrc, szNewsDefault);
  479.       ofn.lpstrFile         = szNewsSrc;
  480.       ofn.nMaxFile          = sizeof(szNewsSrc);
  481.       ofn.lpstrDefExt       = "";
  482.     
  483.       fNewsFound = GetOpenFileName(&ofn);
  484.       if (fNewsFound)
  485.       {
  486.         HFILE hf;
  487.         OFSTRUCT ofs;
  488.         if (OpenFile(szNewsSrc, &ofs, OF_EXIST) == HFILE_ERROR)
  489.         {
  490.           hf = OpenFile(szNewsSrc, &ofs, OF_CREATE);
  491.           /* (Optionally write some default newsgroups here... */
  492.           _lclose(hf);
  493.         }
  494.       }
  495.     }
  496.   }
  497.  
  498.   if (fProfileFound && fNewsFound) return 0;
  499.   return (-1);
  500. }
  501.  
  502.  
  503. /*  Locate the WinVN.ini and NewSrc files... */
  504. int fnLocateFiles (HINSTANCE hInstance, LPSTR lpCmdLine)
  505. {
  506.   int result;
  507.   result = LocIniSrc(hInstance, lpCmdLine);
  508.   if (!result)
  509.   {
  510.     TRACE("WinVN.INI file located: %s\n", szAppProFile);
  511.     TRACE("NewSrc file located:    %s\n", szNewsSrc);
  512.     WritePrivateProfileString(PROFTYPE, "Newsrc",
  513.             szNewsSrc, szAppProFile);
  514.   }
  515.   return(result);
  516. @
  517.  
  518.  
  519. 1.5
  520. log
  521. @win32 fixes, comments changed
  522. @
  523. text
  524. @d3 1
  525. a3 1
  526.  * $Id: ini_news.c 1.5 1994/08/09  15:30:00  brydon Exp $
  527. d5 3
  528. d138 1
  529. a138 1
  530. #ifdef GetFileAttributes
  531. d141 2
  532. a142 1
  533. #else
  534. d160 1
  535. d162 1
  536. a162 2
  537.     stat = GetFileAttributes(szFileSrc);
  538.     if((stat == 0xFFFFFFFF) || !(stat & FILE_ATTRIBUTE_NORMAL))
  539. d182 2
  540. a183 2
  541.   char szIniDef[] = "WinVN.ini";   // ' .ini' default filename
  542.   char szNewsDefault[] = "NewSrc"; // 'newsrc' default filename
  543. d223 1
  544. a223 1
  545.         szNewsDefault, CHECK_DIR | CHECK_FILE);
  546. d350 1
  547. a350 1
  548.  // ofn.lpstrFilter       = (Filled in below)
  549. d354 2
  550. a355 2
  551.  // ofn.lpstrFile         = (Filled in below)
  552.  // ofn.nMaxFile          = (Filled in below)
  553. d368 1
  554. a368 1
  555.  // ofn.lpstrDefExt       = (Filled in below)
  556. d392 1
  557. a392 1
  558.      // ofn.lpstrInitialDir = ...
  559. d414 1
  560. a468 2
  561.  
  562.  
  563. @
  564.  
  565.  
  566. 1.4
  567. log
  568. @cleanup and fixes for win32
  569. @
  570. text
  571. @a0 1
  572.  
  573. d2 5
  574. d8 3
  575. a10 2
  576.  * $Id: ini_news.c 1.3 1993/12/08 01:28:01 rushing Exp $
  577.  * $Log: ini_news.c $
  578. d28 1
  579. a31 1
  580. #define defTempStringSize 128
  581. d33 19
  582. d53 17
  583. a69 1
  584.   This function looks for the .Ini file and the NewsSrc file.
  585. a70 6
  586.   The search order is: Command Line               Unique filenames
  587.                        Environment                Standard filenames
  588.                        Application Directory      Standard filenames
  589.                        Windows Directory          Standard filenames
  590.                        Windows System Directory   Standard filenames
  591.                        the path                   Standard filenames
  592. a71 1
  593.  
  594. d74 3
  595. a76 1
  596.   filename of the NewSrc file.
  597. d99 4
  598. a102 26
  599.   If the files do not exist but the path's do and if they contain the
  600.   standard file(s), szAppProFile is set to "c:\WinVn\WinVn.Ini",
  601.   szNewsSrc is set to "c:\Tom\NewSrc" and the function returns Zero.
  602.  
  603.   If the NewSrc file is not found first by it's unique name and then by the
  604.   standard name in the defined directory, the .ini path is searched for the
  605.   standard NewSrc filename and if this file is found, the path and name
  606.   are returned.
  607.  
  608.   If the command line entry is just a name, the search path is the following:
  609.            the current drive/directory
  610.            windows directory
  611.            windows system directory
  612.            the application directory
  613.            the path
  614.  
  615.   The above behavior may lead to the use of the wrong information files if the
  616.   standard names are used. It is recommended that unique names be used.
  617.  
  618.   If the .Ini file or the NewSrc file is/are not found, first by Name
  619.   then by Path with standard names, a warning is displayed and the
  620.   function continues to search for the file(s) in the order described
  621.   above ( Environment, Appication directory, ...etc).
  622.  
  623.   The intent of this is to allow multiple and unique .Ini and NewsSrc
  624.   location as well and an exhaustive attempt to locate the files.
  625. a103 6
  626.   [Additions to the function/program shold be to popup dialog boxes for the
  627.   necessary information if not found or it is incorrect. Maybe later!]
  628.  
  629.   H. Brydon: I added the dialog boxes to find files not found by the above,
  630.   and create new, empty files if required.  1994/01/25
  631.  
  632. d106 2
  633. a107 1
  634. /*-*xx********************************************************************/
  635. a108 1
  636.  
  637. d110 3
  638. a112 2
  639. BOOL ProbeFilePath(char *szFileSrc, char *szPath, char *szFname, BOOL bChk)
  640. { int i;
  641. d115 35
  642. a149 13
  643.   /* (Enhancement possibility: we can do better checking for directory
  644.       files and can get rid of the bChk variable.  We can use API call
  645.       GetFileAttributes that can check whether or not a file is a 
  646.       directory (ask for FILE_ATTRIBUTE_DIRECTORY)...  - H. Brydon )  */
  647.   lstrcpy(szFileSrc, szPath);
  648.   i = lstrlen(szPath);
  649.   if(i)
  650.   { if (szFileSrc[i-1] != '\\') lstrcat(szFileSrc, "\\");
  651.   }
  652.   lstrcat(szFileSrc, szFname);
  653.   if (OpenFile (szFileSrc, &ofb, OF_EXIST) != HFILE_ERROR)
  654.   { lstrcpy(szFileSrc, ofb.szPathName);
  655.     return TRUE;
  656. d152 10
  657. a161 2
  658.   if (bChk)
  659.   { lstrcpy(szFileSrc, szPath);
  660. d163 2
  661. a164 1
  662.     { lstrcpy(szFileSrc, ofb.szPathName);
  663. a167 3
  664.   
  665.   // other tests can go here...
  666.   
  667. a172 2
  668.  
  669.  
  670. d174 3
  671. a176 3
  672. int fnLocateFiles (HINSTANCE hInstance, LPSTR lpCmdLine)
  673. { char szPath[defTempStringSize];
  674.   char szWPath[defTempStringSize];
  675. a179 1
  676.   char szEnv[] = "WINVN";          // environment variable
  677. d194 3
  678. a196 2
  679.     lstrcpy (szPath, lpCmdLine);
  680.     iRvalue = lstrlen (szPath);
  681. d200 2
  682. a201 2
  683.       if (szPath[iRvalue] == ' ')
  684.       { szPath[iRvalue] = 0;
  685. d207 5
  686. a211 4
  687.     { /* two entries on command line */
  688.       fProfileFound = ProbeFilePath(szAppProFile, szPath, szIniDef,TRUE);
  689.       fNewsFound = ProbeFilePath(szNewsSrc, &szPath[iRvalue + 1], 
  690. szNewsDefault,TRUE);
  691. d215 5
  692. a219 3
  693.     { /* single command line entry - assume it is a path and a file name */
  694.       fProfileFound = ProbeFilePath(szAppProFile, szPath, szIniDef,FALSE);
  695.       fNewsFound = ProbeFilePath(szNewsSrc, szPath, szNewsDefault, FALSE);
  696. d227 1
  697. a227 1
  698.   if ((lpEnvStr = getenv (szEnv)) == NULL)
  699. d229 1
  700. a229 2
  701.     AnsiLowerBuff (szEnv, lstrlen (szEnv));
  702.     lpEnvStr = getenv (szEnv);
  703. d234 1
  704. a234 1
  705.     lstrcpy (szPath, lpEnvStr);
  706. d236 1
  707. d238 2
  708. a239 1
  709.       fProfileFound = ProbeFilePath(szAppProFile, szPath, szIniDef,FALSE);
  710. d242 2
  711. a243 2
  712.       fNewsFound = ProbeFilePath(szNewsSrc, &szPath[iRvalue + 1], 
  713. szNewsDefault, FALSE);
  714. d250 18
  715. d269 1
  716. a269 1
  717.   if ((iRvalue = GetModuleFileName(hInstance, szWPath, defTempStringSize)))
  718. d279 1
  719. d281 2
  720. a282 1
  721.       fProfileFound = ProbeFilePath(szAppProFile, szWPath, szIniDef, FALSE);
  722. d285 2
  723. a286 1
  724.       fNewsFound = ProbeFilePath(szNewsSrc, szWPath, szNewsDefault, FALSE);
  725. d292 16
  726. a307 17
  727. /*  Note:  The following two code segments are written and tested but
  728. *    commented out because they are believed to be superfluous.  Just
  729. *    searching for the files on the current path (below) looks in these
  730. *    directories.  If I am wrong, then please uncomment this code.  It has
  731. *    been tested properly and works...  HAB  */
  732.  
  733.  
  734.       /* Look in the Windows Directory */
  735. //  if ((iRvalue = (int) GetWindowsDirectory (szPath, defTempStringSize)))
  736. //  { if (!fProfileFound)
  737. //      fProfileFound = ProbeFilePath(szAppProFile, szPath, szIniDef, FALSE);
  738. //  
  739. //    if (!fNewsFound)
  740. //      fNewsFound = ProbeFilePath(szNewsSrc, szPath, szNewsDefault, FALSE);
  741. //  
  742. //    if (fProfileFound && fNewsFound) return 0;
  743. //   }
  744. d310 7
  745. d318 3
  746. d322 2
  747. a323 10
  748.       /* Try the Windows System Directory */
  749. //  if ((iRvalue = (int) GetSystemDirectory (szPath, defTempStringSize)))
  750. //  { if (!fProfileFound)
  751. //      fProfileFound = ProbeFilePath(szAppProFile, szPath, szIniDef, FALSE);
  752. //
  753. //    if (!fNewsFound)
  754. //      fNewsFound = ProbeFilePath(szNewsSrc, szPath, szNewsDefault, FALSE);
  755. //
  756. //    if (fProfileFound && fNewsFound) return 0;
  757. //  }
  758. d328 2
  759. a329 1
  760.   szPath[0] = '\0';
  761. d331 2
  762. a332 1
  763.     fProfileFound = ProbeFilePath(szAppProFile, szPath, szIniDef, FALSE);
  764. d335 2
  765. a336 1
  766.     fNewsFound = ProbeFilePath(szNewsSrc, szPath, szNewsDefault, FALSE);
  767. d358 4
  768. a361 4
  769. #ifdef WIN32
  770.     | OFN_NONETWORKBUTTON
  771. #endif      
  772.       | OFN_NOREADONLYRETURN;
  773. d370 2
  774. a371 9
  775.     { char szCreated[32];
  776.  
  777.    // The following code supposedly used to work with older MS and Borland
  778.    // compilers, but doesn't now (definitely not with MSVC/NT 1.0)
  779.    // static char *szFilter[] = { "Init Files (*.INI)", "*.ini",
  780.    //                             "All Files (*.*)",    "*.*",
  781.    //                             "",""};
  782.    
  783.    // ofn.lpstrFilter       = szFilter[0];
  784. d375 1
  785. d380 1
  786. d383 2
  787. a384 1
  788.       { char dbuffer[9];
  789. d386 1
  790. d390 4
  791. a393 2
  792.         _strdate(dbuffer);
  793.         _strtime(tbuffer);
  794. d395 4
  795. a398 3
  796.         lstrcpy(szCreated, dbuffer);
  797.         lstrcat(szCreated, " ");
  798.         lstrcat(szCreated, tbuffer);
  799. d400 3
  800. a402 2
  801.         WritePrivateProfileString(szAppName, "Created",
  802.           szCreated, szAppProFile);
  803. d405 18
  804. a422 3
  805.    
  806.     if (!fNewsFound)
  807.     { ofn.lpstrFilter       =
  808. d425 1
  809. d432 2
  810. a433 1
  811.       { HFILE hf;
  812. d450 2
  813. a451 6
  814.  
  815.  
  816.  
  817. int 
  818. old_fnLocateFiles (HINSTANCE hInstance, LPSTR lpCmdLine)
  819.  
  820. d453 11
  821. a463 202
  822.  
  823.   char szPath[defTempStringSize];
  824.   char szNews[defTempStringSize];
  825.   char szTemp[defTempStringSize];
  826.  
  827.   char szEnv[] = "WINVN";
  828.   char szIni[] = ".Ini";
  829.   char szNewsDefault[] = "NewSrc";
  830.  
  831.   BOOL fNewsFound = FALSE;
  832.   BOOL fProfileFound = FALSE;
  833.  
  834.   int iRvalue;
  835.  
  836.   LPSTR lpEnvStr;
  837.   OFSTRUCT ofOpenBuffer;
  838.  
  839.   ofOpenBuffer.cBytes = sizeof (OFSTRUCT);
  840.  
  841.   while (1)
  842.     {
  843.       /* Look at the Command Line */
  844.       if (*lpCmdLine != '\0')
  845.     {           /* path | path and file */
  846.       lstrcpy (szPath, lpCmdLine);
  847.       iRvalue = lstrlen (szPath);
  848.  
  849.       while (iRvalue--)
  850.         {           /* check for two arguments */
  851.           if (szPath[iRvalue] == ' ')
  852.         {
  853.           szPath[iRvalue] = 0;
  854.           break;
  855.         }
  856.         }
  857.  
  858.       if (iRvalue > 0)
  859.         {           /* two entries on command line */
  860.           lstrcpy (szNews, &szPath[iRvalue + 1]);
  861.           lstrcpy (szTemp, szNews);
  862.  
  863.           /* assume it is a path and a filename */
  864.           if (OpenFile (szNews, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  865.         {
  866.           lstrcpy (szNewsSrc, szNews);
  867.           fNewsFound = TRUE;
  868.         }
  869.           else
  870.         {
  871.           /* assume it is just a path name and look for NEWSSRC */
  872.           lstrcpy (szNews, szTemp);
  873.           iRvalue = lstrlen (szNews);
  874.           if (szNews[iRvalue - 1] != '\\')
  875.             {
  876.               lstrcat (szNews, "\\");
  877.             }
  878.           lstrcat (szNews, szNewsDefault);
  879.  
  880.           if (OpenFile (szNews, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  881.             {
  882.               fNewsFound = TRUE;
  883.               lstrcpy (szNewsSrc, szNews);
  884.             }
  885.           else
  886.             {       /* assume it has a bad filename */
  887.               while (iRvalue--)
  888.             {
  889.               if (szTemp[iRvalue] == '\\')
  890.                 {
  891.                   szTemp[iRvalue + 1] = 0;
  892.                   break;
  893.                 }
  894.             }
  895.  
  896.               lstrcat (szTemp, szNewsDefault);
  897.               if (OpenFile (szTemp, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  898.             {
  899.               fNewsFound = TRUE;
  900.               lstrcpy (szNewsSrc, szTemp);
  901.             }
  902.             }
  903.  
  904.           if (!fNewsFound)
  905.             {
  906.               /* need to add a dialog that the user may enter the 
  907.                * information! */
  908.               MessageBox (NULL,
  909.             "Can not use the Command Line NewsSrc Information!",
  910.                   "Soft Error",
  911.                   MB_OK | MB_ICONQUESTION);
  912.             }
  913.         }
  914.  
  915.           /* looking for Ini, assume it is a path and a file name */
  916.           if (OpenFile (szPath, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  917.         {
  918.           fProfileFound = TRUE;
  919.           lstrcpy (szAppProFile, szPath);
  920.         }
  921.           else
  922.         {
  923.  
  924.           /* assume it is just a path name and look for winvn.ini */
  925.           lstrcpy (szTemp, szPath);
  926.           iRvalue = lstrlen (szTemp);
  927.           if (szTemp[iRvalue - 1] != '\\')
  928.             {
  929.               lstrcat (szTemp, "\\");
  930.             }
  931.           lstrcat (szTemp, szEnv);
  932.           lstrcat (szTemp, szIni);
  933.  
  934.           if (OpenFile (szTemp, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  935.             {
  936.               fProfileFound = TRUE;
  937.               lstrcpy (szAppProFile, szTemp);
  938.             }
  939.           else
  940.             {       /* assume a bad filename */
  941.               lstrcpy (szTemp, szPath);
  942.               while (iRvalue--)
  943.             {
  944.               if (szTemp[iRvalue] == '\\')
  945.                 {
  946.                   szTemp[iRvalue + 1] = 0;
  947.                   break;
  948.                 }
  949.             }
  950.  
  951.               lstrcat (szTemp, szEnv);
  952.               lstrcat (szTemp, szIni);
  953.  
  954.               if (OpenFile (szTemp, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  955.             {
  956.               fProfileFound = TRUE;
  957.               lstrcpy (szAppProFile, szTemp);
  958.             }
  959.             }
  960.  
  961.           if (!fProfileFound)
  962.             {
  963.               /* need to add a dialog so that the user may */
  964.               /* enter/correct the information! */
  965.               MessageBox (NULL,
  966.                 "Can not use the Command Line Ini Information!",
  967.                   "Soft Error",
  968.                   MB_OK | MB_ICONQUESTION);
  969.  
  970.             }
  971.  
  972.         }
  973.  
  974.           if (fProfileFound && !fNewsFound)
  975.         { /* try the .Ini path for the standard NewsSrc */
  976.           iRvalue = lstrlen (szPath);
  977.           while (iRvalue--)
  978.             {
  979.               if (szPath[iRvalue] == '\\')
  980.             {
  981.               szPath[++iRvalue] = 0;
  982.               break;
  983.             }
  984.             }
  985.  
  986.           lstrcpy (szNews, szPath);
  987.           lstrcat (szNews, szNewsDefault);
  988.           if (OpenFile (szNews, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  989.             {
  990.               fNewsFound = TRUE;
  991.               lstrcpy (szNewsSrc, szNews);
  992.               break;
  993.             }
  994.  
  995.         }
  996.  
  997.         }
  998.       else
  999.         {           /* single command line entry */
  1000.           /* assume it is a path and a file name */
  1001.           lstrcpy (szTemp, szPath);
  1002.  
  1003.           if (OpenFile (szTemp, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1004.         {
  1005.           lstrcpy (szAppProFile, szTemp);
  1006.           fProfileFound = TRUE;
  1007.  
  1008.           /* Use the ini path and look for NewsSrc */
  1009.           iRvalue = lstrlen (szPath);
  1010.           lstrcpy (szTemp, szPath);
  1011.           if (szTemp[iRvalue - 1] != '\\')
  1012.             {
  1013.               lstrcat (szTemp, "\\");
  1014.             }
  1015.           lstrcat (szTemp, szNewsDefault);
  1016.  
  1017.           if (OpenFile (szTemp, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1018.             {
  1019.               lstrcpy (szNewsSrc, szTemp);
  1020.               fNewsFound = TRUE;
  1021.               break;
  1022.             }
  1023.         }
  1024. a464 197
  1025.           /* could not find .Ini or NewsSrc assume it is just a */
  1026.           /* path name and look for winvn.ini */
  1027.           iRvalue = lstrlen (szPath);
  1028.           if (szPath[iRvalue - 1] != '\\')
  1029.         {
  1030.           lstrcat (szPath, "\\");
  1031.         }
  1032.           lstrcpy (szTemp, szPath);
  1033.  
  1034.           if (!fProfileFound)
  1035.         {
  1036.           lstrcat (szTemp, szEnv);
  1037.           lstrcat (szTemp, szIni);
  1038.  
  1039.           if (OpenFile (szTemp, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1040.             {
  1041.               lstrcpy (szAppProFile, szTemp);
  1042.               fProfileFound = TRUE;
  1043.             }
  1044.  
  1045.           lstrcpy (szTemp, szPath);
  1046.           lstrcat (szTemp, szNewsDefault);
  1047.           if (OpenFile (szTemp, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1048.             {
  1049.               lstrcpy (szNewsSrc, szTemp);
  1050.               fNewsFound = TRUE;
  1051.             }
  1052.  
  1053.         }
  1054.  
  1055.           if (fProfileFound && fNewsFound)
  1056.         {
  1057.           break;
  1058.         }
  1059.  
  1060.           /* need to add a dialog that the user may enter the */
  1061.           /* information! */
  1062.           lstrcpy (szTemp, "Could not use the Command Line Information for ");
  1063.  
  1064.           if (!fProfileFound && !fNewsFound)
  1065.         {
  1066.           lstrcat (szTemp, ".Ini and NewsSrc");
  1067.         }
  1068.           else if (!fProfileFound)
  1069.         {
  1070.           lstrcat (szTemp, szIni);
  1071.         }
  1072.           else
  1073.         {
  1074.           lstrcat (szTemp, szNewsDefault);
  1075.         }
  1076.  
  1077.           MessageBox (NULL, szTemp, "Soft Error", MB_OK | MB_ICONQUESTION);
  1078.  
  1079.         }
  1080.  
  1081.     }
  1082.  
  1083.  
  1084.       /* Look in the Environment for a path */
  1085.       if ((lpEnvStr = getenv (szEnv)) == NULL)
  1086.     {
  1087.       AnsiLowerBuff (szEnv, lstrlen (szEnv));
  1088.       lpEnvStr = getenv (szEnv);
  1089.     }
  1090.  
  1091.       if (lpEnvStr && (iRvalue = lstrlen (lpEnvStr)))
  1092.     {           /* found environment varible, check it out */
  1093.       lstrcpy (szPath, lpEnvStr);
  1094.       if (szPath[iRvalue - 1] != '\\')
  1095.         {
  1096.           lstrcat (szPath, "\\");
  1097.         }
  1098.  
  1099.       if (!fProfileFound)
  1100.         {           /* look for the .Ini file */
  1101.           lstrcpy (szAppProFile, szPath);
  1102.           lstrcat (szAppProFile, szEnv);
  1103.           lstrcat (szAppProFile, szIni);
  1104.  
  1105.           if (OpenFile (szAppProFile, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1106.         {
  1107.           fProfileFound = TRUE;
  1108.         }
  1109.         }
  1110.  
  1111.       if (!fNewsFound)
  1112.         {           /* look for the .NewsSrc file */
  1113.           lstrcpy (szNewsSrc, szPath);
  1114.           lstrcat (szNewsSrc, szNewsDefault);
  1115.  
  1116.           if (OpenFile (szNewsSrc, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1117.         {
  1118.           fNewsFound = TRUE;
  1119.         }
  1120.         }
  1121.  
  1122.       if (fProfileFound && fNewsFound)
  1123.         {
  1124.           break;
  1125.         }
  1126.  
  1127.     }
  1128.  
  1129.  
  1130.       /* Look in WinVn's Directory */
  1131.       if ((iRvalue = GetModuleFileName (hInstance, szPath, defTempStringSize)))
  1132.     {
  1133.       while (iRvalue--)
  1134.         {           /* remove the module name */
  1135.           if (szPath[iRvalue] == '\\')
  1136.         {
  1137.           szPath[++iRvalue] = 0;
  1138.           break;
  1139.         }
  1140.         }
  1141.  
  1142.       if (!fProfileFound)
  1143.         {           /* look for the .Ini file */
  1144.           lstrcpy (szAppProFile, szPath);
  1145.           lstrcat (szAppProFile, szEnv);
  1146.           lstrcat (szAppProFile, szIni);
  1147.           if (OpenFile (szAppProFile, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1148.         {
  1149.           fProfileFound = TRUE;
  1150.         }
  1151.         }
  1152.  
  1153.       if (!fNewsFound)
  1154.         {           /* look for the NewsSrc file */
  1155.           lstrcpy (szNewsSrc, szPath);
  1156.           lstrcat (szNewsSrc, szNewsDefault);
  1157.  
  1158.           if (OpenFile (szNewsSrc, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1159.         {
  1160.           fNewsFound = TRUE;
  1161.         }
  1162.         }
  1163.  
  1164.       if (fProfileFound && fNewsFound)
  1165.         {
  1166.           break;
  1167.         }
  1168.  
  1169.     }
  1170.  
  1171.  
  1172.       /* Look in the Windows's Directory */
  1173.       if ((iRvalue = (int) GetWindowsDirectory (szPath, defTempStringSize)))
  1174.     {
  1175.       lstrcat (szPath, "\\");
  1176.  
  1177.       if (!fProfileFound)
  1178.         {           /* look for the .Ini file */
  1179.           lstrcpy (szAppProFile, szPath);
  1180.           lstrcat (szAppProFile, szEnv);
  1181.           lstrcat (szAppProFile, szIni);
  1182.           if (OpenFile (szAppProFile, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1183.         {
  1184.           fProfileFound = TRUE;
  1185.         }
  1186.         }
  1187.  
  1188.       if (!fNewsFound)
  1189.         {           /* look for the NewsSrc file */
  1190.           lstrcpy (szNewsSrc, szPath);
  1191.           lstrcat (szNewsSrc, szNewsDefault);
  1192.  
  1193.           if (OpenFile (szNewsSrc, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1194.         {
  1195.           fNewsFound = TRUE;
  1196.         }
  1197.         }
  1198.  
  1199.       if (fProfileFound && fNewsFound)
  1200.         {
  1201.           break;
  1202.         }
  1203.  
  1204.     }
  1205.  
  1206.  
  1207.       /* Try the Windows System's Directory */
  1208.       if ((iRvalue = (int) GetSystemDirectory (szPath, defTempStringSize)))
  1209.     {
  1210.       lstrcat (szPath, "\\");
  1211.  
  1212.       if (!fProfileFound)
  1213.         {           /* look for the .Ini file */
  1214.           lstrcpy (szAppProFile, szPath);
  1215.           lstrcat (szAppProFile, szEnv);
  1216.           lstrcat (szAppProFile, szIni);
  1217.           if (OpenFile (szAppProFile, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1218.         {
  1219.           fProfileFound = TRUE;
  1220.         }
  1221.         }
  1222. a465 59
  1223.       if (!fNewsFound)
  1224.         {           /* look for the NewsSrc file */
  1225.           lstrcpy (szNewsSrc, szPath);
  1226.           lstrcat (szNewsSrc, szNewsDefault);
  1227.  
  1228.           if (OpenFile (szNewsSrc, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1229.         {
  1230.           fNewsFound = TRUE;
  1231.         }
  1232.         }
  1233.  
  1234.       if (fProfileFound && fNewsFound)
  1235.         {
  1236.           break;
  1237.         }
  1238.  
  1239.     }
  1240.  
  1241.       /* Last chance, Try the current path */
  1242.       if (!fProfileFound)
  1243.     {           /* look for the .Ini file */
  1244.       lstrcpy (szAppProFile, szEnv);
  1245.       lstrcat (szAppProFile, szIni);
  1246.       if (OpenFile (szAppProFile, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1247.         {
  1248.           fProfileFound = TRUE;
  1249.         }
  1250.     }
  1251.  
  1252.       if (!fNewsFound)
  1253.     {           /* look for the NewsSrc file */
  1254.       lstrcpy (szNewsSrc, szNewsDefault);
  1255.  
  1256.       if (OpenFile (szNewsSrc, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1257.         {
  1258.           fNewsFound = TRUE;
  1259.         }
  1260.     }
  1261.  
  1262.       if (fProfileFound && fNewsFound)
  1263.     {
  1264.       break;
  1265.     }
  1266.  
  1267.       /* No potatoes, RTFM
  1268.        * need to add a dialog that the user may enter the information!
  1269.        */
  1270.       MessageBox (NULL,
  1271.           "Can Not Find Your .Ini File or NewsSrc File",
  1272.           "Fatal Error",
  1273.           MB_OK | MB_ICONEXCLAMATION);
  1274.  
  1275.       return (-1);
  1276.  
  1277.     }
  1278.  
  1279.   return (0);
  1280.  
  1281. }
  1282. @
  1283.  
  1284.  
  1285. 1.3
  1286. log
  1287. @new version box and cr lf consistency
  1288. @
  1289. text
  1290. @d4 5
  1291. a8 2
  1292.  * $Id: ini-news.c 1.2 1993/07/07 19:52:22 rushing Exp rushing $
  1293.  * $Log: ini-news.c $
  1294. d24 2
  1295. a25 1
  1296.  
  1297. d51 1
  1298. a51 1
  1299.   1. c:\WinVn\My.Ini<sp>c:\Tom\NewsSrc.Tom  => both unique names
  1300. d53 2
  1301. a54 1
  1302.   2. c:\Tom<sp>c:\Tom\NewsSrc.Tom        => standard .Ini, unique NewSrc
  1303. d56 1
  1304. a56 1
  1305.   3. c:\Tom\TomVn.ini                    => unique .Ini, Standard NewSrc
  1306. d58 2
  1307. a59 1
  1308.   4. c:\Tom                              => standard .Ini, Standard NewSrc
  1309. d91 2
  1310. a92 2
  1311.   Additions to the function/program shold be to popup dialog boxes for the
  1312.   necessary information if not found or it is incorrect. Maybe later!
  1313. d94 3
  1314. d101 271
  1315. d373 1
  1316. a373 1
  1317. fnLocateFiles (HINSTANCE hInstance, LPSTR lpCmdLine)
  1318. d398 232
  1319. a629 232
  1320.       if (*lpCmdLine != NULL)
  1321.     {            /* path | path and file */
  1322.       lstrcpy (szPath, lpCmdLine);
  1323.       iRvalue = lstrlen (szPath);
  1324.  
  1325.       while (iRvalue--)
  1326.         {            /* check for two arguments */
  1327.           if (szPath[iRvalue] == ' ')
  1328.         {
  1329.           szPath[iRvalue] = 0;
  1330.           break;
  1331.         }
  1332.         }
  1333.  
  1334.       if (iRvalue > 0)
  1335.         {            /* two entries on command line */
  1336.           lstrcpy (szNews, &szPath[iRvalue + 1]);
  1337.           lstrcpy (szTemp, szNews);
  1338.  
  1339.           /* assume it is a path and a filename */
  1340.           if (OpenFile (szNews, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1341.         {
  1342.           lstrcpy (szNewsSrc, szNews);
  1343.           fNewsFound = TRUE;
  1344.         }
  1345.           else
  1346.         {
  1347.           /* assume it is just a path name and look for NEWSSRC */
  1348.           lstrcpy (szNews, szTemp);
  1349.           iRvalue = lstrlen (szNews);
  1350.           if (szNews[iRvalue - 1] != '\\')
  1351.             {
  1352.               lstrcat (szNews, "\\");
  1353.             }
  1354.           lstrcat (szNews, szNewsDefault);
  1355.  
  1356.           if (OpenFile (szNews, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1357.             {
  1358.               fNewsFound = TRUE;
  1359.               lstrcpy (szNewsSrc, szNews);
  1360.             }
  1361.           else
  1362.             {        /* assume it has a bad filename */
  1363.               while (iRvalue--)
  1364.             {
  1365.               if (szTemp[iRvalue] == '\\')
  1366.                 {
  1367.                   szTemp[iRvalue + 1] = 0;
  1368.                   break;
  1369.                 }
  1370.             }
  1371.  
  1372.               lstrcat (szTemp, szNewsDefault);
  1373.               if (OpenFile (szTemp, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1374.             {
  1375.               fNewsFound = TRUE;
  1376.               lstrcpy (szNewsSrc, szTemp);
  1377.             }
  1378.             }
  1379.  
  1380.           if (!fNewsFound)
  1381.             {
  1382.               /* need to add a dialog that the user may enter the 
  1383.                * information! */
  1384.               MessageBox (NULL,
  1385.             "Can not use the Command Line NewsSrc Information!",
  1386.                   "Soft Error",
  1387.                   MB_OK | MB_ICONQUESTION);
  1388.             }
  1389.         }
  1390.  
  1391.           /* looking for Ini, assume it is a path and a file name */
  1392.           if (OpenFile (szPath, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1393.         {
  1394.           fProfileFound = TRUE;
  1395.           lstrcpy (szAppProFile, szPath);
  1396.         }
  1397.           else
  1398.         {
  1399.  
  1400.           /* assume it is just a path name and look for winvn.ini */
  1401.           lstrcpy (szTemp, szPath);
  1402.           iRvalue = lstrlen (szTemp);
  1403.           if (szTemp[iRvalue - 1] != '\\')
  1404.             {
  1405.               lstrcat (szTemp, "\\");
  1406.             }
  1407.           lstrcat (szTemp, szEnv);
  1408.           lstrcat (szTemp, szIni);
  1409.  
  1410.           if (OpenFile (szTemp, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1411.             {
  1412.               fProfileFound = TRUE;
  1413.               lstrcpy (szAppProFile, szTemp);
  1414.             }
  1415.           else
  1416.             {        /* assume a bad filename */
  1417.               lstrcpy (szTemp, szPath);
  1418.               while (iRvalue--)
  1419.             {
  1420.               if (szTemp[iRvalue] == '\\')
  1421.                 {
  1422.                   szTemp[iRvalue + 1] = 0;
  1423.                   break;
  1424.                 }
  1425.             }
  1426.  
  1427.               lstrcat (szTemp, szEnv);
  1428.               lstrcat (szTemp, szIni);
  1429.  
  1430.               if (OpenFile (szTemp, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1431.             {
  1432.               fProfileFound = TRUE;
  1433.               lstrcpy (szAppProFile, szTemp);
  1434.             }
  1435.             }
  1436.  
  1437.           if (!fProfileFound)
  1438.             {
  1439.               /* need to add a dialog so that the user may */
  1440.               /* enter/correct the information! */
  1441.               MessageBox (NULL,
  1442.                 "Can not use the Command Line Ini Information!",
  1443.                   "Soft Error",
  1444.                   MB_OK | MB_ICONQUESTION);
  1445.  
  1446.             }
  1447.  
  1448.         }
  1449.  
  1450.           if (fProfileFound && !fNewsFound)
  1451.         { /* try the .Ini path for the standard NewsSrc */
  1452.           iRvalue = lstrlen (szPath);
  1453.           while (iRvalue--)
  1454.             {
  1455.               if (szPath[iRvalue] == '\\')
  1456.             {
  1457.               szPath[++iRvalue] = 0;
  1458.               break;
  1459.             }
  1460.             }
  1461.  
  1462.           lstrcpy (szNews, szPath);
  1463.           lstrcat (szNews, szNewsDefault);
  1464.           if (OpenFile (szNews, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1465.             {
  1466.               fNewsFound = TRUE;
  1467.               lstrcpy (szNewsSrc, szNews);
  1468.               break;
  1469.             }
  1470.  
  1471.         }
  1472.  
  1473.         }
  1474.       else
  1475.         {            /* single command line entry */
  1476.           /* assume it is a path and a file name */
  1477.           lstrcpy (szTemp, szPath);
  1478.  
  1479.           if (OpenFile (szTemp, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1480.         {
  1481.           lstrcpy (szAppProFile, szTemp);
  1482.           fProfileFound = TRUE;
  1483.  
  1484.           /* Use the ini path and look for NewsSrc */
  1485.           iRvalue = lstrlen (szPath);
  1486.           lstrcpy (szTemp, szPath);
  1487.           if (szTemp[iRvalue - 1] != '\\')
  1488.             {
  1489.               lstrcat (szTemp, "\\");
  1490.             }
  1491.           lstrcat (szTemp, szNewsDefault);
  1492.  
  1493.           if (OpenFile (szTemp, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1494.             {
  1495.               lstrcpy (szNewsSrc, szTemp);
  1496.               fNewsFound = TRUE;
  1497.               break;
  1498.             }
  1499.         }
  1500.  
  1501.           /* could not find .Ini or NewsSrc assume it is just a */
  1502.           /* path name and look for winvn.ini */
  1503.           iRvalue = lstrlen (szPath);
  1504.           if (szPath[iRvalue - 1] != '\\')
  1505.         {
  1506.           lstrcat (szPath, "\\");
  1507.         }
  1508.           lstrcpy (szTemp, szPath);
  1509.  
  1510.           if (!fProfileFound)
  1511.         {
  1512.           lstrcat (szTemp, szEnv);
  1513.           lstrcat (szTemp, szIni);
  1514.  
  1515.           if (OpenFile (szTemp, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1516.             {
  1517.               lstrcpy (szAppProFile, szTemp);
  1518.               fProfileFound = TRUE;
  1519.             }
  1520.  
  1521.           lstrcpy (szTemp, szPath);
  1522.           lstrcat (szTemp, szNewsDefault);
  1523.           if (OpenFile (szTemp, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1524.             {
  1525.               lstrcpy (szNewsSrc, szTemp);
  1526.               fNewsFound = TRUE;
  1527.             }
  1528.  
  1529.         }
  1530.  
  1531.           if (fProfileFound && fNewsFound)
  1532.         {
  1533.           break;
  1534.         }
  1535.  
  1536.           /* need to add a dialog that the user may enter the */
  1537.           /* information! */
  1538.           lstrcpy (szTemp, "Could not use the Command Line Information for ");
  1539.  
  1540.           if (!fProfileFound && !fNewsFound)
  1541.         {
  1542.           lstrcat (szTemp, ".Ini and NewsSrc");
  1543.         }
  1544.           else if (!fProfileFound)
  1545.         {
  1546.           lstrcat (szTemp, szIni);
  1547.         }
  1548.           else
  1549.         {
  1550.           lstrcat (szTemp, szNewsDefault);
  1551.         }
  1552. d631 1
  1553. a631 1
  1554.           MessageBox (NULL, szTemp, "Soft Error", MB_OK | MB_ICONQUESTION);
  1555. d633 1
  1556. a633 1
  1557.         }
  1558. d635 1
  1559. a635 1
  1560.     }
  1561. d640 4
  1562. a643 4
  1563.     {
  1564.       AnsiLowerBuff (szEnv, lstrlen (szEnv));
  1565.       lpEnvStr = getenv (szEnv);
  1566.     }
  1567. d646 34
  1568. a679 34
  1569.     {            /* found environment varible, check it out */
  1570.       lstrcpy (szPath, lpEnvStr);
  1571.       if (szPath[iRvalue - 1] != '\\')
  1572.         {
  1573.           lstrcat (szPath, "\\");
  1574.         }
  1575.  
  1576.       if (!fProfileFound)
  1577.         {            /* look for the .Ini file */
  1578.           lstrcpy (szAppProFile, szPath);
  1579.           lstrcat (szAppProFile, szEnv);
  1580.           lstrcat (szAppProFile, szIni);
  1581.  
  1582.           if (OpenFile (szAppProFile, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1583.         {
  1584.           fProfileFound = TRUE;
  1585.         }
  1586.         }
  1587.  
  1588.       if (!fNewsFound)
  1589.         {            /* look for the .NewsSrc file */
  1590.           lstrcpy (szNewsSrc, szPath);
  1591.           lstrcat (szNewsSrc, szNewsDefault);
  1592.  
  1593.           if (OpenFile (szNewsSrc, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1594.         {
  1595.           fNewsFound = TRUE;
  1596.         }
  1597.         }
  1598.  
  1599.       if (fProfileFound && fNewsFound)
  1600.         {
  1601.           break;
  1602.         }
  1603. d681 1
  1604. a681 1
  1605.     }
  1606. d686 36
  1607. a721 36
  1608.     {
  1609.       while (iRvalue--)
  1610.         {            /* remove the module name */
  1611.           if (szPath[iRvalue] == '\\')
  1612.         {
  1613.           szPath[++iRvalue] = 0;
  1614.           break;
  1615.         }
  1616.         }
  1617.  
  1618.       if (!fProfileFound)
  1619.         {            /* look for the .Ini file */
  1620.           lstrcpy (szAppProFile, szPath);
  1621.           lstrcat (szAppProFile, szEnv);
  1622.           lstrcat (szAppProFile, szIni);
  1623.           if (OpenFile (szAppProFile, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1624.         {
  1625.           fProfileFound = TRUE;
  1626.         }
  1627.         }
  1628.  
  1629.       if (!fNewsFound)
  1630.         {            /* look for the NewsSrc file */
  1631.           lstrcpy (szNewsSrc, szPath);
  1632.           lstrcat (szNewsSrc, szNewsDefault);
  1633.  
  1634.           if (OpenFile (szNewsSrc, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1635.         {
  1636.           fNewsFound = TRUE;
  1637.         }
  1638.         }
  1639.  
  1640.       if (fProfileFound && fNewsFound)
  1641.         {
  1642.           break;
  1643.         }
  1644. d723 1
  1645. a723 1
  1646.     }
  1647. d728 24
  1648. a751 2
  1649.     {
  1650.       lstrcat (szPath, "\\");
  1651. d753 4
  1652. a756 26
  1653.       if (!fProfileFound)
  1654.         {            /* look for the .Ini file */
  1655.           lstrcpy (szAppProFile, szPath);
  1656.           lstrcat (szAppProFile, szEnv);
  1657.           lstrcat (szAppProFile, szIni);
  1658.           if (OpenFile (szAppProFile, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1659.         {
  1660.           fProfileFound = TRUE;
  1661.         }
  1662.         }
  1663.  
  1664.       if (!fNewsFound)
  1665.         {            /* look for the NewsSrc file */
  1666.           lstrcpy (szNewsSrc, szPath);
  1667.           lstrcat (szNewsSrc, szNewsDefault);
  1668.  
  1669.           if (OpenFile (szNewsSrc, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1670.         {
  1671.           fNewsFound = TRUE;
  1672.         }
  1673.         }
  1674.  
  1675.       if (fProfileFound && fNewsFound)
  1676.         {
  1677.           break;
  1678.         }
  1679. d758 1
  1680. a758 1
  1681.     }
  1682. d763 2
  1683. a764 2
  1684.     {
  1685.       lstrcat (szPath, "\\");
  1686. d766 21
  1687. a786 26
  1688.       if (!fProfileFound)
  1689.         {            /* look for the .Ini file */
  1690.           lstrcpy (szAppProFile, szPath);
  1691.           lstrcat (szAppProFile, szEnv);
  1692.           lstrcat (szAppProFile, szIni);
  1693.           if (OpenFile (szAppProFile, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1694.         {
  1695.           fProfileFound = TRUE;
  1696.         }
  1697.         }
  1698.  
  1699.       if (!fNewsFound)
  1700.         {            /* look for the NewsSrc file */
  1701.           lstrcpy (szNewsSrc, szPath);
  1702.           lstrcat (szNewsSrc, szNewsDefault);
  1703.  
  1704.           if (OpenFile (szNewsSrc, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1705.         {
  1706.           fNewsFound = TRUE;
  1707.         }
  1708.         }
  1709.  
  1710.       if (fProfileFound && fNewsFound)
  1711.         {
  1712.           break;
  1713.         }
  1714. d788 6
  1715. a793 1
  1716.     }
  1717. d797 8
  1718. a804 8
  1719.     {            /* look for the .Ini file */
  1720.       lstrcpy (szAppProFile, szEnv);
  1721.       lstrcat (szAppProFile, szIni);
  1722.       if (OpenFile (szAppProFile, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1723.         {
  1724.           fProfileFound = TRUE;
  1725.         }
  1726.     }
  1727. d807 2
  1728. a808 2
  1729.     {            /* look for the NewsSrc file */
  1730.       lstrcpy (szNewsSrc, szNewsDefault);
  1731. d810 5
  1732. a814 5
  1733.       if (OpenFile (szNewsSrc, &ofOpenBuffer, OF_EXIST) != HFILE_ERROR)
  1734.         {
  1735.           fNewsFound = TRUE;
  1736.         }
  1737.     }
  1738. d817 3
  1739. a819 3
  1740.     {
  1741.       break;
  1742.     }
  1743. d825 3
  1744. a827 3
  1745.           "Can Not Find Your .Ini File or NewsSrc File",
  1746.           "Fatal Error",
  1747.           MB_OK | MB_ICONEXCLAMATION);
  1748. @
  1749.  
  1750.  
  1751. 1.2
  1752. log
  1753. @check value returned from getenv for NULL
  1754. @
  1755. text
  1756. @d1 1
  1757. d4 1
  1758. a4 1
  1759.  * $Id: ini-news.c 1.1 1993/02/16 20:53:50 rushing Exp rushing $
  1760. d6 3
  1761. @
  1762.  
  1763.  
  1764. 1.1
  1765. log
  1766. @Initial revision
  1767. @
  1768. text
  1769. @d3 4
  1770. a6 2
  1771.  * $Id$
  1772.  * $Log$
  1773. d8 1
  1774. d361 1
  1775. a361 1
  1776.       if ((iRvalue = lstrlen (lpEnvStr)))
  1777. @
  1778.